package com.tool;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.swing.JTextField;

public class ConnTools {
	/**
	 *	返回List集合
	 */
	public static List<JTextField> getList(JTextField[] text)
	{
		List<JTextField> list = new ArrayList<JTextField>();
		for(int i=0;i< text.length ;i++)
		{
			list.add(text[i]);
		}
		return list;
	}
	
	/**
	 * @param text
	 * @param map
	 * @return
	 * 			返回经过修改的sql语句
	 */
	public static String getMap(JTextField[] text,Map<String,String> map){
		String str=null;
		String sqls="";
		int foot=0;
		String[] jl = {"b_name","b_type","b_price","b_num","b_company","b_indate"};
		for(JTextField num:ConnTools.getList(text)) {
			if(num.getText().equals(""))
			{
				foot++;
				continue;
			}
			else
			{
				map.put(jl[foot] , num.getText());
				foot++;
			}
		}
		Set<Map.Entry<String,String>> set = map.entrySet();
		Iterator<Map.Entry<String, String>> it = set.iterator();
		while( it.hasNext() )
		{
			Map.Entry<String, String> me = it.next();
			if(it.hasNext())
			{
				sqls += me.getKey() + "='" + me.getValue() +"' ,";
			}
			else
			{
				sqls += me.getKey() + "='" + me.getValue() +"'";
			}
		}
		return sqls;
	}
}
